using System;
using System.Web.UI.WebControls;

namespace Sedna.Core.Controller.Configurations
{
	public class DataGridPagerStyleConfiguration : GenericConfiguration, IDataGridPagerStyleConfiguration
	{



		private ImsPagerMode imsPagerMode = ImsPagerMode.TextNextPrev;

		private string prevHtml = "Previous";//this should be an Image name (without relative path) in case of an image pager; if it is a text pager than it should be a default label
		private string nextHtml = "Next";

		private string prevKey = "prevKey";
		private string nextKey = "nextKey";

		private string keyPrefix;

		private string prevImg = "prev_page.gif";
		private string nextImg = "next_page.gif";


		public ImsPagerMode ImsPagerMode
		{
			get { return imsPagerMode; }
			set { imsPagerMode = value; }
		}


		public string PrevHtml
		{
			get { return prevHtml; }
			set { prevHtml = value; }
		}

		public string NextHtml
		{
			get { return nextHtml; }
			set { nextHtml = value; }
		}

		public string PrevKey
		{
			get { return prevKey; }
			set { prevKey = value; }
		}

		public string NextKey
		{
			get { return nextKey; }
			set { nextKey = value; }
		}

		public string KeyPrefix
		{
			get { return keyPrefix; }
			set { keyPrefix = value; }
		}


		public PagerMode PagerMode
		{
			get
			{
				switch(imsPagerMode)
				{
					case ImsPagerMode.TextNextPrev:
					case ImsPagerMode.ImageNextPrev:
						return PagerMode.NextPrev;
					case ImsPagerMode.NumericPages:
						return PagerMode.NumericPages;
					default:
						throw new Exception("Unknown PagerMode");
				}
			}
		}

		public string GetPrevHtml()
		{
			return GetPrevHtml(null);
		}

		public string GetPrevHtml(string prefix)
		{
			if(imsPagerMode == ImsPagerMode.TextNextPrev)
			{
				return MessageManager.GetMessage(ExtractPrefix(prefix) + "." + prevKey, PrincipalWrapper.Culture, prevHtml);
			}

            throw new NotSupportedException("Only ImsPagerMode.TextNextPrev is supported");
		}

		public string GetNextHtml()
		{
			return GetNextHtml(null);
		}

		public string GetNextHtml(string prefix)
		{
			if(imsPagerMode == ImsPagerMode.TextNextPrev)
			{
				return MessageManager.GetMessage(ExtractPrefix(prefix) + "." + nextKey, PrincipalWrapper.Culture, nextHtml);
			}

            throw new NotSupportedException("Only ImsPagerMode.TextNextPrev is supported");
        }

		private string ExtractPrefix(string prefix)
		{
			return prefix!=null?prefix:keyPrefix;
		}


		public string GetPrevImg()
		{
			return prevImg;
		}

		public string GetNextImg()
		{
			return nextImg;
		}


	}
}
